#include "lowpass.h"

LowPassFilter::LowPassFilter() : y1(0.0f) {
    calculateCoefficients(2.0f);  // Default 2Hz cutoff
}

LowPassFilter::LowPassFilter(float cutoff_freq) : y1(0.0f) {
    calculateCoefficients(cutoff_freq);
}

void LowPassFilter::calculateCoefficients(float cutoff_freq) {
    const float fs = 5000.0f;  // 5kHz sampling frequency
    a1 = expf(-2.0f * PI * cutoff_freq / fs);
    b0 = 1.0f - a1;
}

float LowPassFilter::update(float input) {
    // First order low-pass filter implementation
    // y[n] = a1*y[n-1] + b0*x[n]
    y1 = a1 * y1 + b0 * input;
    return y1;
}
